﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Telerik.Web.UI;
using System.Data;

namespace Utilities
{
    public class Utility
    {
        public static void BindRadComboBox(RadComboBox theRadComboBox, DataSet dataSource, string dataTextField, string dataValueField, bool hasEmptyItem)
        {
            try
            {
                if (theRadComboBox != null && dataSource != null)
                {
                    theRadComboBox.DataTextField = dataTextField;
                    theRadComboBox.DataValueField = dataValueField;

                    theRadComboBox.DataSource = dataSource;
                    theRadComboBox.DataBind();

                    if (hasEmptyItem == true && theRadComboBox.Items.Count > 0)
                    {
                        RadComboBoxItem item = new RadComboBoxItem();
                        item.Text = string.Empty;
                        item.Value = string.Empty;
                        item.Selected = true;

                        theRadComboBox.Items.Insert(0, item);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }

        public static string Parser(string message)
        {
            string strResult = string.Empty;

            strResult = message.Replace("\n", "\\n");
            strResult = strResult.Replace("\r" + "\\n", "\\n");
            strResult = strResult.Replace("'", "\\'");

            return strResult;
        }

        public static void ShowMessageBox(System.Web.UI.Page page, string message)
        {
            string strScript = "<script type='text/javascript'>";
            strScript += "alert('" + Parser(message) + "');";
            strScript += "</script>";

            if (!page.ClientScript.IsStartupScriptRegistered("clientScript"))
            {
                page.ClientScript.RegisterStartupScript(page.GetType(), "clientScript", strScript);
            }
        }

    }
}
